import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller/note_add_ctl.dart';

class AddNoteScreen extends StatelessWidget {
  final AddNoteController controller = Get.put(AddNoteController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Add Note'),
        actions: [
          Obx(
                () => DropdownButton<String>(
              value: controller.selectedCategory.value,
              items: controller.homeController.categories
                  .map<DropdownMenuItem<String>>((String category) {
                return DropdownMenuItem<String>(
                  value: category,
                  child: Text(category),
                );
              }).toList(),
              onChanged: (String? newValue) {
                if (newValue != null) {
                  controller.selectedCategory.value = newValue;
                }
              },
            ),
          ),
          IconButton(
            icon: Icon(Icons.save),
            onPressed: () {
              controller.addNote(); // 保存笔记
            },
          ),
        ],
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            // 标题输入框
            TextField(
              controller: controller.titleController,
              decoration: InputDecoration(
                hintText: '主题',
                border:InputBorder.none,
                hintStyle: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  color: Colors.black26
                ),
              ),
              style: TextStyle(
                fontSize: 20,
                color: Colors.black,
                fontWeight: FontWeight.bold
              ),
            ),
            SizedBox(height: 8),
            Divider(
              height: 0.5,
            ),
            // 内容输入框
            Expanded(
              child: TextField(
                controller: controller.contentController,
                decoration: InputDecoration(
                  hintText: '正文',
                  border: InputBorder.none,
                  hintStyle: TextStyle(
                    fontSize: 16,
                    color: Colors.black26
                  )
                ),
                maxLines: null, // 支持多行输入
                expands: true, // 填充剩余空间
              ),
            ),
          ],
        ),
      ),
    );
  }
}